package com.xtravel.tweet.database.dto;

import com.xtravel.common.database.dto.DtoBase;

import java.util.ArrayList;
import java.util.List;

public class Tweet extends DtoBase {
    public String tweetId;
    public String content;
    public String tweetUrl;
    public String title;
    public String dtCreatedTime;
    public int retweetCount;
    public int commentCount;
    public int likeCount;
    public boolean isPerfect;
    public String tags;
    public List<TweetSource> tweetSources = new ArrayList<TweetSource>();
    public List<Wisher> wisher = new ArrayList<Wisher>();
    public List<AppLive> lives = new ArrayList<AppLive>();
    private List<TweetSource> imageSources;
    private List<TweetSource> linkSources;
    private Long createdTime;
    private Long onlineTime;
    public int viewCount;
    public int wishCount;
    public boolean isCollected;
    public boolean isView;
    public boolean isWish;


    public Long getOnlineTime() {
        return onlineTime;
    }

    public void setOnlineTime(Long onlineTime) {
        this.onlineTime = onlineTime;
    }

    public Tweet() {
    }

    public Tweet(int id, String tweetId, String content, String tweetUrl, String title, String dtCreatedTime, int retweetCount, int commentCount, int likeCount, boolean
            isPerfect, List<TweetSource> tweetSources, String tags) {
        super(id);
        this.objId = Long.valueOf(id);
        this.tweetId = tweetId;
        this.content = content;
        this.tweetUrl = tweetUrl;
        this.title = title;
        this.dtCreatedTime = dtCreatedTime;
        this.retweetCount = retweetCount;
        this.commentCount = commentCount;
        this.likeCount = likeCount;
        this.isPerfect = isPerfect;
        this.tweetSources = tweetSources;
        this.wisher = wisher;
        this.tags = tags;
        imageSources = new ArrayList<TweetSource>();
        linkSources = new ArrayList<TweetSource>();
        setImageLinkSources();
    }

    public List<TweetSource> getTweetSources() {
        if (tweetSources == null) {
            tweetSources = new ArrayList<TweetSource>();
        }
        return tweetSources;
    }

    public void setTweetSources(List<TweetSource> tweetSources) {
        this.tweetSources = tweetSources;
        setImageLinkSources();
    }

    public List<Wisher> getWisher() {
        if (wisher == null) {
            wisher = new ArrayList<Wisher>();
        }
        return wisher;
    }

    public void setWisher(List<Wisher> wisher) {
        this.wisher = wisher;
    }

    public List<AppLive> getLives() {
        if(lives == null){
            lives = new ArrayList<>();
        }
        return lives;
    }

    public void setLives(List<AppLive> lives) {
        this.lives = lives;
    }

    public List<TweetSource> getImageSources() {
        if (imageSources == null || imageSources.size() == 0) {
            setImageLinkSources();
        }

        return imageSources;
    }

    public List<TweetSource> getLinkSources() {
        if (linkSources == null || linkSources.size() == 0) {
            setImageLinkSources();
        }

        return linkSources;
    }

    private void setImageLinkSources() {
        if (tweetSources == null) {
            tweetSources = new ArrayList<TweetSource>();
        }

        if (linkSources == null) {
            linkSources = new ArrayList<TweetSource>();
        }

        if (imageSources == null) {
            imageSources = new ArrayList<TweetSource>();
        }

        for (TweetSource item : tweetSources) {
            if (item.type == 1) {
                linkSources.add(item);
            } else {
                imageSources.add(item);
            }
        }
    }
}
